// var i;
// var $item_Shop_BoxItem_UIBindings = require("./Item_Shop_BoxItem_UIBindings");
// var $resKeeper = require("./ResKeeper");
// var $excel = require("./Excel");
// var $hallManager = require("./HallManager");
// var $playerDataManager = require("./PlayerDataManager");
// var $eventManager = require("./EventManager");
// var $evenType = require("./EvenType");
// var $const_Hall = require("./Const_Hall");
// var $uIManager = require("./UIManager");
// var $bundleConfig = require("./BundleConfig");
// var $uIConfig_Home = require("./UIConfig_Home");
// var $hallGlobalVariable = require("./HallGlobalVariable");
// var $aDManager = require("./ADManager");
// var $commonUtils = require("./CommonUtils");
// var $const_Common = require("./Const_Common");
// var I = cc._decorator;
// var M = I.ccclass;
// var E = I.property;
// var x = I.inspector;
// var C = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         t.isStart = !0;
//         t.childIndex = 0;
//         t.delateTime = 0;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onLoad = function () {
//         this.auto_ui.addClickListener(this._clickListener, this);
//     };
//     t.prototype.StartSet = function (e, t) {
//         if (void 0 === t) {
//             t = null;
//         }
//         if (t) {
//             this.timeLabel = t;
//         }
//         this.childIndex = e;
//         var o = $excel.Excel.shopControl(1);
//         if (this.isStart) {
//             this.isStart = !1;
//             this.auto_ui.txt_nameLabel.string = 0 == e ? "普通礼盒" : "精致礼盒";
//             this.auto_ui.txt_priceLabel.string = 0 == e ? "" + o.boxPrice : "" + o.bigBoxPrice;
//             this.auto_ui.node_ptBg.active = 0 == e;
//             this.auto_ui.node_jzBg.active = 0 != e;
//         }
//         var n = $excel.Excel.shopBoxLevel($hallManager.HallMgr.shopData.boxLevel + 1);
//         if (0 == e) {
//             this.rewards = n.rewards;
//         } else {
//             this.rewards = n.bigRewards;
//         }
//         var i = cc.Color.GREEN;
//         var a = "普通";
//         if (this.rewards[2]) {
//             i = new cc.Color(223, 84, 219, 255);
//             a = "稀有";
//         } else {
//             if (this.rewards[1]) {
//                 a = "高级";
//                 i = new cc.Color(12, 224, 255, 255);
//             }
//         }
//         this.auto_ui.txt_mustGetLabel.string = a;
//         this.auto_ui.txt_mustGetLabel.node.color = i;
//         if (0 == e) {
//             this.auto_ui.btn_videoBuyBtn.interactable = o.box1BuyCount - $hallManager.HallMgr.shopData.box1BuyCount > 0;
//         } else {
//             this.auto_ui.btn_videoBuyBtn.interactable = o.box2BuyCount - $hallManager.HallMgr.shopData.box2BuyCount > 0;
//         }
//         this.auto_ui.txt_timeLabel.node.active = !this.auto_ui.btn_videoBuyBtn.interactable;
//     };
//     t.prototype._clickListener = function (e) {
//         switch (e) {
//             case this.auto_ui.btn_videoBuyBtn:
//                 this.VideoBuyBox(null);
//                 break;
//             case this.auto_ui.btn_buyBtn:
//                 this.BuyThis(!1);
//                 break;
//             case this.auto_ui.btn_showInfoBtn:
//                 var t = new $const_Hall.BoxInfoData();
//                 t.type = this.childIndex;
//                 t.clickCallBack = this.VideoBuyBox.bind(this);
//                 $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_BoxInfo, t);
//         }
//     };
//     t.prototype.VideoBuyBox = function (e) {
//         var t = this;
//         var o = "商城视频购买普通宝箱";
//         if (0 == this.childIndex) {
//             o = "商城视频购买精致宝箱";
//         }
//         $aDManager.ADMgr.showRewardedVideo(o, function () {
//             t.BuyThis(!0);
//             if (e) {
//                 e();
//             }
//         });
//     };
//     t.prototype.BuyThis = function (e) {
//         var t = $excel.Excel.shopControl(1);
//         var o;
//         if (0 == this.childIndex) {
//             o = t.boxPrice;
//         } else {
//             o = t.bigBoxPrice;
//         }
//         if (e) {
//             0 == this.childIndex
//                 ? $hallManager.HallMgr.shopData.box1BuyCount++
//                 : $hallManager.HallMgr.shopData.box2BuyCount++;
//             this.GetReward(o);
//             this.StartSet(this.childIndex);
//         } else {
//             if ($playerDataManager.PlayerDataMgr.SubDiamond(o)) {
//                 var n = "商城钻石购买普通宝箱";
//                 if (0 == this.childIndex) {
//                     n = "商城钻石购买精致宝箱";
//                 }
//                 $commonUtils.default.SendPoint($const_Common.SendPointType.外围打点, n);
//                 this.GetReward(o);
//                 this.StartSet(this.childIndex);
//             }
//         }
//     };
//     t.prototype.GetReward = function (e) {
//         var t = this;
//         var o = $excel.Excel.shopBoxLevel($hallManager.HallMgr.shopData.boxLevel + 1);
//         var n = new $const_Hall.OpenBoxViewData();
//         n.boxType = this.childIndex;
//         n.boxCount = 0;
//         var i;
//         var a = 0;
//         if (0 == this.childIndex) {
//             a = o.moneyCount || 0;
//             i = [o.rewards[0] || 0, o.rewards[1] || 0, o.rewards[2] || 0];
//         } else {
//             a = o.bigMoneyCount || 0;
//             i = [o.bigRewards[0] || 0, o.bigRewards[1] || 0, o.bigRewards[2] || 0];
//         }
//         n.boxCount = i[0] + i[1] + i[2];
//         n.clickCallBack = function () {
//             var n = [[], [], []];
//             $excel.Excel.shuiguo_all.forEach(function (e) {
//                 if ($playerDataManager.PlayerDataMgr.GetEquipDataById(e.id).isUnLock && -1 != e.isShow) {
//                     n[e.quality - 1].push(e);
//                 }
//             });
//             var r = new Map();
//             for (var c = 0; c < i.length; c++) {
//                 var s = i[c];
//                 if (0 != n[c].length) {
//                     for (var u = 0; u < s; u++) {
//                         var p = Math.floor(Math.random() * n[c].length);
//                         var h = n[c][p];
//                         if (!r.has(h.id)) {
//                             r.set(h.id, 0);
//                         }
//                         var v = r.get(h.id);
//                         v++;
//                         r.set(h.id, v);
//                     }
//                 }
//             }
//             var b = new $const_Hall.GetItemsData();
//             b.ids = [];
//             b.counts = [];
//             if (a > 0) {
//                 b.ids.push($hallGlobalVariable.default.goldId);
//                 b.counts.push(a);
//             }
//             r.forEach(function (e, t) {
//                 b.ids.push(t);
//                 b.counts.push(e);
//             });
//             b.clickCallBack = function () {
//                 for (var n = 0; n < b.ids.length; n++) {
//                     var i = b.ids[n];
//                     var a = b.counts[n];
//                     if (i == $hallGlobalVariable.default.goldId) {
//                         $playerDataManager.PlayerDataMgr.AddGold(a);
//                     } else {
//                         $playerDataManager.PlayerDataMgr.AddEquipFragments(i, a);
//                     }
//                 }
//                 t.GetRewardEnd({
//                     needDiamond: e,
//                     nextExp: o.exp
//                 });
//             };
//             $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_GetItems, b);
//         };
//         $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_OpenBox, n);
//     };
//     t.prototype.GetRewardEnd = function (e) {
//         var t =
//             $hallManager.HallMgr.shopData.boxLevel < $excel.Excel.shopBoxLevel_all.size - 1 &&
//             $hallManager.HallMgr.shopData.boxExp + e.needDiamond >= e.nextExp;
//         $hallManager.HallMgr.shopData.boxExp += e.needDiamond;
//         $hallManager.HallMgr.SaveShopData();
//         $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.HallResetShopBox);
//         if (t) {
//             $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_BoxUpLevel);
//         }
//     };
//     t.prototype.update = function (e) {
//         this.delateTime += e;
//         if (this.delateTime > 0.2) {
//             this.delateTime = 0;
//             if (!this.auto_ui.btn_videoBuyBtn.interactable && this.timeLabel) {
//                 this.auto_ui.txt_timeLabel.string = this.timeLabel.string;
//             }
//         }
//     };
//     __decorate([E($item_Shop_BoxItem_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return __decorate([M], t);
// })($resKeeper.default);
// exports.default = C;

// import Item_Shop_BoxItem_UIBindings from "./Item_Shop_BoxItem_UIBindings";
// import ResKeeper from "./ResKeeper";
// import {Excel} from "./Excel";
// import {HallMgrInstance} from "./HallManager";
// import {PlayerDataMgr} from "./PlayerDataManager";
// import {EventMgrInstance} from "./EventManager";
// import {EVENT_TYPE} from "./EvenType";
// import UIManager from "./UIManager";
// import {BundleNames} from "./BundleConfig";
// import HallGlobalVariable from "./HallGlobalVariable";
// import { ADMgr } from "./ADManager";
// import CommonUtils from "./CommonUtils";
// import { BoxInfoData, GetItemsData, OpenBoxViewData } from "./Const_Hall";
// import { SendPointType } from "./Const_Common";
// import { UIView_Home } from "./UIConfig_Home";


// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * 建议类名：ShopBoxItem
//  */
// @ccclass
// class Item_Shop_BoxItem extends ResKeeper {
//     @property(Item_Shop_BoxItem_UIBindings)
//     auto_ui: Item_Shop_BoxItem_UIBindings | null = null;

//     isStart: boolean = true;
//     childIndex: number = 0;
//     delateTime: number = 0;
//     timeLabel: cc.Label | null = null;
//     rewards: any[] = [];

//     onLoad(): void {
//         this.auto_ui?.addClickListener(this._clickListener, this);
//     }

//     /**
//      * 建议方法名：initialize
//      * @param index 礼盒类型索引
//      * @param timeLabel 时间标签
//      */
//     StartSet(index: number, timeLabel?: cc.Label | null): void {
//         if (timeLabel) {
//             this.timeLabel = timeLabel;
//         }
//         this.childIndex = index;
//         const shopControl = Excel.shopControl(1);

//         if (this.isStart) {
//             this.isStart = false;
//             this.auto_ui!.txt_nameLabel.string = index === 0 ? "普通礼盒" : "精致礼盒";
//             this.auto_ui!.txt_priceLabel.string = index === 0 ? `${shopControl.boxPrice}` : `${shopControl.bigBoxPrice}`;
//             this.auto_ui!.node_ptBg.active = index === 0;
//             this.auto_ui!.node_jzBg.active = index !== 0;
//         }

//         const shopBoxLevel = Excel.shopBoxLevel(HallMgrInstance.shopData.boxLevel + 1);
//         this.rewards = index === 0 ? shopBoxLevel.rewards : shopBoxLevel.bigRewards;

//         let color = cc.Color.GREEN;
//         let label = "普通";

//         if (this.rewards[2]) {
//             color = new cc.Color(223, 84, 219, 255);
//             label = "稀有";
//         } else if (this.rewards[1]) {
//             color = new cc.Color(12, 224, 255, 255);
//             label = "高级";
//         }

//         this.auto_ui!.txt_mustGetLabel.string = label;
//         this.auto_ui!.txt_mustGetLabel.node.color = color;

//         if (index === 0) {
//             this.auto_ui!.btn_videoBuyBtn.interactable = shopControl.box1BuyCount - HallMgrInstance.shopData.box1BuyCount > 0;
//         } else {
//             this.auto_ui!.btn_videoBuyBtn.interactable = shopControl.box2BuyCount - HallMgrInstance.shopData.box2BuyCount > 0;
//         }

//         this.auto_ui!.txt_timeLabel.node.active = !this.auto_ui!.btn_videoBuyBtn.interactable;
//     }

//     /**
//      * 建议方法名：handleClick
//      * @param event 点击事件
//      */
//     private _clickListener(event: cc.Button): void {
//         switch (event) {
//             case this.auto_ui!.btn_videoBuyBtn:
//                 this.VideoBuyBox(null);
//                 break;
//             case this.auto_ui!.btn_buyBtn:
//                 this.BuyThis(false);
//                 break;
//             case this.auto_ui!.btn_showInfoBtn:
//                 const boxInfoData = new BoxInfoData();
//                 boxInfoData.type = this.childIndex;
//                 boxInfoData.clickCallBack = this.VideoBuyBox.bind(this);
//                 UIManager.open(BundleNames.Home, UIView_Home.UI_BoxInfo, boxInfoData);
//                 break;
//         }
//     }

//     /**
//      * 建议方法名：purchaseBoxWithVideo
//      * @param callback 回调函数
//      */
//     VideoBuyBox(callback: Function | null): void {
//         const description = this.childIndex === 0 ? "商城视频购买普通宝箱" : "商城视频购买精致宝箱";
//         ADMgr.showRewardedVideo(description, () => {
//             this.BuyThis(true);
//             if (callback) {
//                 callback();
//             }
//         });
//     }

//     /**
//      * 建议方法名：purchaseBox
//      * @param isVideo 是否通过视频购买
//      */
//     BuyThis(isVideo: boolean): void {
//         const shopControl = Excel.shopControl(1);
//         const price = this.childIndex === 0 ? shopControl.boxPrice : shopControl.bigBoxPrice;

//         if (isVideo) {
//             if (this.childIndex === 0) {
//                 HallMgrInstance.shopData.box1BuyCount++;
//             } else {
//                 HallMgrInstance.shopData.box2BuyCount++;
//             }
//             this.GetReward(price);
//             this.StartSet(this.childIndex);
//         } else {
//             if (PlayerDataMgr.SubDiamond(price)) {
//                 const description = this.childIndex === 0 ? "商城钻石购买普通宝箱" : "商城钻石购买精致宝箱";
//                 CommonUtils.SendPoint(SendPointType.外围打点, description);
//                 this.GetReward(price);
//                 this.StartSet(this.childIndex);
//             }
//         }
//     }

//     /**
//      * 建议方法名：retrieveReward
//      * @param price 礼盒价格
//      */
//     GetReward(price: number): void {
//         const shopBoxLevel = Excel.shopBoxLevel(HallMgrInstance.shopData.boxLevel + 1);
//         const openBoxViewData = new OpenBoxViewData();
//         openBoxViewData.boxType = this.childIndex;
//         openBoxViewData.boxCount = 0;

//         let moneyCount = 0;
//         let rewards: number[] = [];

//         if (this.childIndex === 0) {
//             moneyCount = shopBoxLevel.moneyCount || 0;
//             rewards = [shopBoxLevel.rewards[0] || 0, shopBoxLevel.rewards[1] || 0, shopBoxLevel.rewards[2] || 0];
//         } else {
//             moneyCount = shopBoxLevel.bigMoneyCount || 0;
//             rewards = [shopBoxLevel.bigRewards[0] || 0, shopBoxLevel.bigRewards[1] || 0, shopBoxLevel.bigRewards[2] || 0];
//         }

//         openBoxViewData.boxCount = rewards.reduce((acc, val) => acc + val, 0);
//         openBoxViewData.clickCallBack = () => {
//             const availableItems: any[][] = [[], [], []];
//             Excel.shuiguo_all.forEach((item: any) => {
//                 if (PlayerDataMgr.GetEquipDataById(item.id).isUnLock && item.isShow !== -1) {
//                     availableItems[item.quality - 1].push(item);
//                 }
//             });

//             const rewardMap = new Map < number, number> ();
//             rewards.forEach((reward, index) => {
//                 if (availableItems[index].length > 0) {
//                     for (let i = 0; i < reward; i++) {
//                         const randomIndex = Math.floor(Math.random() * availableItems[index].length);
//                         const selectedItem = availableItems[index][randomIndex];
//                         rewardMap.set(selectedItem.id, (rewardMap.get(selectedItem.id) || 0) + 1);
//                     }
//                 }
//             });

//             const getItemsData = new GetItemsData();
//             getItemsData.ids = [];
//             getItemsData.counts = [];

//             if (moneyCount > 0) {
//                 getItemsData.ids.push(HallGlobalVariable.goldId);
//                 getItemsData.counts.push(moneyCount);
//             }

//             rewardMap.forEach((count, id) => {
//                 getItemsData.ids.push(id);
//                 getItemsData.counts.push(count);
//             });

//             getItemsData.clickCallBack = () => {
//                 getItemsData.ids.forEach((id, index) => {
//                     const count = getItemsData.counts[index];
//                     if (id === HallGlobalVariable.goldId) {
//                         PlayerDataMgr.AddGold(count);
//                     } else {
//                         PlayerDataMgr.AddEquipFragments(id, count);
//                     }
//                 });

//                 this.GetRewardEnd({
//                     needDiamond: price,
//                     nextExp: shopBoxLevel.exp
//                 });
//             };

//             UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
//         };

//         UIManager.open(BundleNames.Home, UIView_Home.UI_OpenBox, openBoxViewData);
//     }

//     /**
//      * 建议方法名：finalizeReward
//      * @param rewardData 奖励数据
//      */
//     GetRewardEnd(rewardData: { needDiamond: number, nextExp: number }): void {
//         const shopData = HallMgrInstance.shopData;
//         const isLevelUp = shopData.boxLevel < Excel.shopBoxLevel_all.size - 1 && shopData.boxExp + rewardData.needDiamond >= rewardData.nextExp;

//         shopData.boxExp += rewardData.needDiamond;
//         HallMgrInstance.SaveShopData();
//         EventMgrInstance.dispatchEvent(EVENT_TYPE.HallResetShopBox);

//         if (isLevelUp) {
//             UIManager.open(BundleNames.Home, UIView_Home.UI_BoxUpLevel);
//         }
//     }

//     /**
//      * 建议方法名：updateFrame
//      * @param deltaTime 帧间隔时间
//      */
//     update(deltaTime: number): void {
//         this.delateTime += deltaTime;
//         if (this.delateTime > 0.2) {
//             this.delateTime = 0;
//             if (!this.auto_ui!.btn_videoBuyBtn.interactable && this.timeLabel) {
//                 this.auto_ui!.txt_timeLabel.string = this.timeLabel.string;
//             }
//         }
//     }
// }

// export default Item_Shop_BoxItem;

import ItemShopBoxItemUIBindings from "./Item_Shop_BoxItem_UIBindings";
import ResKeeper from "./ResKeeper";
import { Excel } from "./Excel";
import { HallMgr } from "./HallManager";
import { PlayerDataMgr } from "./PlayerDataManager";
import { EventMgrInstance } from "./EventManager";
import { EVENT_TYPE } from "./EvenType";
import UIManager from "./UIManager";
import { BundleNames } from "./BundleConfig";
import FruitDataManager from "./HallGlobalVariable";
import { ADMgr } from "./ADManager";
import { BoxInfoData, GetItemsData, OpenBoxViewData } from "./Const_Hall";
import { UIView_Home } from "./UIConfig_Home";

const { ccclass, property, inspector } = cc._decorator;

/**
 * 建议类名：ShopBoxItem
 */
@ccclass
class ItemShopBoxItem extends ResKeeper {
    @property(ItemShopBoxItemUIBindings)
    auto_ui: ItemShopBoxItemUIBindings | null = null;

    isStart: boolean = true;
    childIndex: number = 0;
    delateTime: number = 0;
    timeLabel: cc.Label | null = null;
    rewards: any[] = [];

    onLoad(): void {
        this.auto_ui?.addClickListener(this._clickListener, this);
    }

    /**
     * 建议方法名：initialize
     * @param index 礼盒类型索引
     * @param timeLabel 时间标签
     */
    initialize(index: number, timeLbl?: cc.Label | null): void {
        if (timeLbl) {
            this.timeLabel = timeLbl;
        }
        this.childIndex = index;
        const shopCtrl = Excel.shopControl(1);

        if (this.isStart) {
            this.isStart = false;
            this.auto_ui!.txt_nameLabel.string = index === 0 ? "普通礼盒" : "精致礼盒";
            this.auto_ui!.txt_priceLabel.string = index === 0 ? `${shopCtrl.boxPrice}` : `${shopCtrl.bigBoxPrice}`;
            this.auto_ui!.node_ptBg.active = index === 0;
            this.auto_ui!.node_jzBg.active = index !== 0;
        }

        const shopBoxLvl = Excel.shopBoxLevel(HallMgr.shopData.boxLevel + 1);
        this.rewards = index === 0 ? shopBoxLvl.rewards : shopBoxLvl.bigRewards;

        let rewardColor = cc.Color.GREEN;
        let rewardLabel = "普通";

        if (this.rewards[2]) {
            rewardColor = new cc.Color(223, 84, 219, 255);
            rewardLabel = "稀有";
        } else if (this.rewards[1]) {
            rewardColor = new cc.Color(12, 224, 255, 255);
            rewardLabel = "高级";
        }

        this.auto_ui!.txt_mustGetLabel.string = rewardLabel;
        this.auto_ui!.txt_mustGetLabel.node.color = rewardColor;

        const buyBtn = this.auto_ui!.btn_videoBuyBtn;
        if (index === 0) {
            buyBtn.interactable = shopCtrl.box1BuyCount - HallMgr.shopData.box1BuyCount > 0;
        } else {
            buyBtn.interactable = shopCtrl.box2BuyCount - HallMgr.shopData.box2BuyCount > 0;
        }

        this.auto_ui!.txt_timeLabel.node.active = !buyBtn.interactable;
    }

    /**
     * 建议方法名：handleClick
     * @param event 点击事件
     */
    private _clickListener(event: cc.Button): void {
        switch (event) {
            case this.auto_ui!.btn_videoBuyBtn:
                this.purchaseBoxWithVideo(null);
                break;
            case this.auto_ui!.btn_buyBtn:
                this.purchaseBox(false);
                break;
            case this.auto_ui!.btn_showInfoBtn:
                const boxInfoData = new BoxInfoData();
                boxInfoData.type = this.childIndex;
                boxInfoData.clickCallBack = this.purchaseBoxWithVideo.bind(this);
                UIManager.open(BundleNames.Home, UIView_Home.UI_BoxInfo, boxInfoData);
                break;
        }
    }

    /**
     * 建议方法名：purchaseBoxWithVideo
     * @param callback 回调函数
     */
    purchaseBoxWithVideo(callback: Function | null): void {
        const description = this.childIndex === 0 ? "商城视频购买普通宝箱" : "商城视频购买精致宝箱";
        ADMgr.showRewardedVideoAd(description, () => {
            this.purchaseBox(true);
            if (callback) {
                callback();
            }
        });
    }

    /**
     * 建议方法名：purchaseBox
     * @param isVideo 是否通过视频购买
     */
    purchaseBox(isVideo: boolean): void {
        const shopCtrl = Excel.shopControl(1);
        const boxPrice = this.childIndex === 0 ? shopCtrl.boxPrice : shopCtrl.bigBoxPrice;

        if (isVideo) {
            if (this.childIndex === 0) {
                HallMgr.shopData.box1BuyCount++;
            } else {
                HallMgr.shopData.box2BuyCount++;
            }
            this.retrieveReward(boxPrice);
            this.initialize(this.childIndex);
        } else {
            if (PlayerDataMgr.subtractDiamond(boxPrice)) {
                // const description = this.childIndex === 0 ? "商城钻石购买普通宝箱" : "商城钻石购买精致宝箱";
                // CommonUtils.sendTrackingEvent(SendPointType.OuterAreaMarking, description);
                this.retrieveReward(boxPrice);
                this.initialize(this.childIndex);
            }
        }
    }

    /**
     * 建议方法名：retrieveReward
     * @param price 礼盒价格
     */
    retrieveReward(boxPrice: number): void {
        const shopBoxLvl = Excel.shopBoxLevel(HallMgr.shopData.boxLevel + 1);
        const openBoxViewData = new OpenBoxViewData();
        openBoxViewData.boxType = this.childIndex;
        openBoxViewData.boxCount = 0;

        let goldCount = 0;
        let rewardList: number[] = [];

        if (this.childIndex === 0) {
            goldCount = shopBoxLvl.moneyCount || 0;
            rewardList = [shopBoxLvl.rewards[0] || 0, shopBoxLvl.rewards[1] || 0, shopBoxLvl.rewards[2] || 0];
        } else {
            goldCount = shopBoxLvl.bigMoneyCount || 0;
            rewardList = [shopBoxLvl.bigRewards[0] || 0, shopBoxLvl.bigRewards[1] || 0, shopBoxLvl.bigRewards[2] || 0];
        }

        openBoxViewData.boxCount = rewardList.reduce((acc, val) => acc + val, 0);
        openBoxViewData.clickCallBack = () => {
            const availableItems: any[][] = [[], [], []];
            Excel.shuiguo_all.forEach((item: any) => {
                if (PlayerDataMgr.getEquipDataById(item.id).isUnLock && item.isShow !== -1) {
                    availableItems[item.quality - 1].push(item);
                }
            });

            const rewardMap = new Map<number, number>();
            rewardList.forEach((reward, index) => {
                if (availableItems[index].length > 0) {
                    for (let i = 0; i < reward; i++) {
                        const randomIndex = Math.floor(Math.random() * availableItems[index].length);
                        const selectedItem = availableItems[index][randomIndex];
                        rewardMap.set(selectedItem.id, (rewardMap.get(selectedItem.id) || 0) + 1);
                    }
                }
            });

            const getItemsData = new GetItemsData();
            getItemsData.ids = [];
            getItemsData.counts = [];

            if (goldCount > 0) {
                getItemsData.ids.push(FruitDataManager.goldId);
                getItemsData.counts.push(goldCount);
            }

            rewardMap.forEach((count, id) => {
                getItemsData.ids.push(id);
                getItemsData.counts.push(count);
            });

            getItemsData.clickCallBack = () => {
                getItemsData.ids.forEach((id, index) => {
                    const count = getItemsData.counts[index];
                    if (id === FruitDataManager.goldId) {
                        PlayerDataMgr.addGold(count);
                    } else {
                        PlayerDataMgr.addEquipFragments(id, count);
                    }
                });

                this.finalizeReward({
                    needDiamond: boxPrice,
                    nextExp: shopBoxLvl.exp
                });
            };

            UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
        };

        UIManager.open(BundleNames.Home, UIView_Home.UI_OpenBox, openBoxViewData);
    }

    /**
     * 建议方法名：finalizeReward
     * @param rewardData 奖励数据
     */
    finalizeReward(rewardData: { needDiamond: number, nextExp: number }): void {
        const shopData = HallMgr.shopData;
        const isLvlUp = shopData.boxLevel < Excel.shopBoxLevel_all.size - 1 && shopData.boxExp + rewardData.needDiamond >= rewardData.nextExp;

        shopData.boxExp += rewardData.needDiamond;
        HallMgr.saveShopData();
        EventMgrInstance.emitEvent(EVENT_TYPE.HallResetShopBox);

        if (isLvlUp) {
            UIManager.open(BundleNames.Home, UIView_Home.UI_BoxUpLevel);
        }
    }

    /**
     * 建议方法名：updateFrame
     * @param deltaTime 帧间隔时间
     */
    update(deltaTime: number): void {
        this.delateTime += deltaTime;
        if (this.delateTime > 0.2) {
            this.delateTime = 0;
            if (!this.auto_ui!.btn_videoBuyBtn.interactable && this.timeLabel) {
                this.auto_ui!.txt_timeLabel.string = this.timeLabel.string;
            }
        }
    }
}

export default ItemShopBoxItem;